# -*- coding: utf-8 -*-
from PyQt5.QtCore import *
import sys
from nanomsg import Socket, PAIR
import rlisYumiPy

yumi = rlisYumiPy.rlisYumi

class NNThread(QThread):
    signalRevErr = pyqtSignal(str) 
    signalRevMsg = pyqtSignal(str) 

    def __init__(self):
        self.so = Socket(PAIR)
        self.ep = 0
        self.working = False

    def send(self,msg):
        try:
            self.so.send(msg)
        except:
            self.signalRevErr.emit("发送失败")

    '''
    addr,ip地址和端口
    addr : string 
    '''
    def connect(self,addr):
        try:
            self.ep = self.so.connect(addr)
        except:
            self.signalRevErr.emit("打开失败")
    
    def run(self):
        while self.working :
            msg = str(self.so.recv()).strip(b'\x00'.decode())
            self.signalRevMsg.emit(msg)
        self.so.close()

        
